import Vue from 'vue';
import Router from 'vue-router';
import Page from '@/view/layout/page';

Vue.use(Router);

const routes = [{
    path: '*',
    redirect: '/error'
  },
  // {
  //   path: '/',
  //   redirect: '/layout/home'
  // },
  {
    path: '/error',
    component: () => import('@/view/error'),
  },
  {
    path: '/layout',
    redirect: 'home',
    component: () => import('@/view/layout'),
    children: [{
        path: 'home',
        component: () => import('@/view/home'),
        meta: {
          title: '首页'
        }
      },
      {
        path: 'user',
        component: () => import('@/view/user'),
        meta: {
          title: '我的'
        }
      },
    ]
  },
  {
    path: '/',
        component: () => import('@/view/home'),
        meta: {
          title: '首页'
        }
  },
  {
    path: '/login',
    component: Page,
    redirect: 'phone',
    children: [{
        path: 'index',
        component: () => import('@/view/login'),
        meta: {
          title: '登录'
        }
      },
      {
        path: 'account',
        component: () => import('@/view/login/account'),
        meta: {
          title: '账号密码登录'
        }
      },
      {
        path: 'phone',
        component: () => import('@/view/login/phone'),
        meta: {
          title: '手机登录'
        }
      },
      {
        path: 'bind',
        component: () => import('@/view/login/bind'),
        meta: {
          title: '绑定微信'
        }
      },
    ]
  },
  {
    name: 'register',
    path: '/register',
    component: () => import('@/view/register'),
    meta: {
      title: '注册'
    }
  },
  {
    path: '/user',
    component: Page,
    children: [{
        path: 'info',
        component: () => import('@/view/user/info'),
        meta: {
          title: '个人信息'
        },
      },
      {
        path: 'perfect',
        component: () => import('@/view/user/perfect'),
        meta: {
          title: '完善信息'
        },
      },
    ]
  },
  {
    path: '/patient',
    component: Page,
    children: [{
        path: 'addEdit',
        component: () => import('@/view/patient/addEdit'),
        meta: {
          title: '新增就诊人'
        },
      },
      {
        path: 'list',
        component: () => import('@/view/patient/list'),
        meta: {
          title: '就诊人管理'
        },
      },
      {
        path: 'select',
        component: () => import('@/view/patient/select'),
        meta: {
          title: '选择就诊人'
        },
      },
    ],
  },
  {
    path: '/pay',
    component: Page,
    children: [
      {
        path: 'list',
        component: () => import('@/view/pay/list'),
        meta: {
          title: '门诊缴费'
        },
      },
      {
        path: 'record',
        component: () => import('@/view/pay/record'),
        meta: {
          title: '门诊缴费记录'
        },
      },
      {
        path: 'detail',
        component: () => import('@/view/pay/detail'),
        meta: {
          title: '缴费详情'
        },
      },
      {
        path: 'success',
        component: () => import('@/view/pay/success'),
        meta: {
          title: '支付成功'
        },
      },
    ],
  },
  {
    path: '/message',
    component: Page,
    children: [
      {
        path: 'list',
        component: () => import('@/view/message/list'),
        meta: {
          title: '消息通知'
        },
      },
    ],
  },
  {
    path: '/office',
    component: Page,
    children: [
      {
        path: 'index',
        component: () => import('@/view/office/index'),
        meta: {
          title: '选择医生'
        },
      },
      // list和doctor都整合到index里，暂时用不上
      {
        path: 'list',
        component: () => import('@/view/office/list'),
        meta: {
          title: '选择科室'
        },
      },
      {
        path: 'doctor',
        component: () => import('@/view/office/doctor'),
        meta: {
          title: '选择医生'
        },
      },
    ],
  },
  {
    path: '/doctor',
    component: Page,
    children: [
      {
        path: 'index',
        component: () => import('@/view/doctor/index'),
        meta: {
          title: '医生信息'
        },
      },{
        path: 'list',
        component: () => import('@/view/doctor/list'),
        meta: {
          title: '选择医生'
        },
      },
    ],
  },
  {
    path: '/appointment',
    component: Page,
    children: [
      {
        path: 'index',
        component: () => import('@/view/appointment/index'),
        meta: {
          title: '确认预约信息'
        },
      },{
        path: 'detail',
        component: () => import('@/view/appointment/detail'),
        meta: {
          title: '预约详情'
        },
      },{
        path: 'success',
        component: () => import('@/view/appointment/success'),
        meta: {
          title: '预约成功'
        },
      },{
        path: 'list',
        component: () => import('@/view/appointment/list'),
        meta: {
          title: '预约挂号记录'
        },
      },
    ],
  },
  {
    path: '/checkIn',
    component: Page,
    children: [{
        path: 'index',
        component: () => import('@/view/checkIn/index'),
        meta: {
          title: '自助报到'
        },
      },{
        path: 'detail',
        component: () => import('@/view/checkIn/detail'),
        meta: {
          title: '候诊查询'
        },
      },
    ]
  },
  {
    path: '/report',
    component: Page,
    children: [{
        path: 'index',
        component: () => import('@/view/report/index'),
        meta: {
          title: '选择报告类型'
        },
      },{
        path: 'list',
        component: () => import('@/view/report/list'),
        meta: {
          title: '报告查询'
        },
      },{
        path: 'detail',
        component: () => import('@/view/report/detail'),
        meta: {
          title: '报告详情'
        },
      },
    ]
  },
  {
    path: '/module',
    component: Page,
    children: [{
        path: 'popupPicker',
        component: () => import('@/view/module/popupPicker'),
        meta: {
          title: '滚动列表选择'
        },
      },
      {
        path: 'searchList',
        component: () => import('@/view/module/searchList'),
        meta: {
          title: '带搜索列表选择'
        },
      },
      {
        path: 'dateRange',
        component: () => import('@/view/module/dateRange'),
        meta: {
          title: '日期区间选择'
        },
      },
      {
        path: 'calendarSelect',
        component: () => import('@/view/module/calendarSelect'),
        meta: {
          title: '日历区间选择'
        },
      },
      {
        path: 'areaSelect',
        component: () => import('@/view/module/areaSelect'),
        meta: {
          title: '地区联动选择'
        },
      },
      {
        path: 'flyDialog',
        component: () => import('@/view/module/flyDialog'),
        meta: {
          title: '自定义弹窗'
        },
      },
      {
        path: 'imageUpload',
        component: () => import('@/view/module/imageUpload'),
        meta: {
          title: '上传'
        },
      },
    ]
  },
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

// router.beforeEach((to, from, next) => {
//   const title = to.meta && to.meta.title;
//   if (title) {
//     document.title = title;
//   }
//   next();
// });

export default new Router({
  // mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({
    y: 0
  }),
  routes: routes
})